from applications.extensions import ma
from marshmallow import fields
from marshmallow import fields, validate

from applications.models import Dept


# police的序列化类
class PoliceOutSchema(ma.Schema):
    id = fields.Integer()
    code =fields.Str()
    name = fields.Str()
    sex = fields.Str()
    birthday = fields.Str()
    id_number = fields.Str()
    native_place = fields.Str()
    address = fields.Str()
    post = fields.Str()
    title = fields.Str()
    dept = fields.Method("get_dept")
    dept_name = fields.Str()

    def get_dept(self, obj):
        if obj.dept_id != None:
            department = Dept.query.filter_by(id=obj.dept_id).first()
            if department is None:
                return None
            else:
                return department.dept_name
        else:
            return None



class PoliceRecordSchema(ma.Schema):
    id = fields.Integer()
    police_id = fields.Integer()
    class_id = fields.Integer()
    score = fields.Integer()
    update_time_time = fields.Str()